[HEADER]	
[/HEADER]	
	
[TEXTURES]
	FILE base 	body.pvr  	LINEAR-LINEAR-LINEAR
[/TEXTURES]	
	
[VERTEXSHADER]	
	NAME VertShader	
	[GLSL_CODE]	
	attribute vec3	inVertex;
	attribute vec3	inNormal;
	attribute vec2	inTexCoord;
	attribute vec4	inBoneIndex;
	attribute vec4	inBoneWeight;
	
	uniform mat4 	ViewProjMatrix;
	uniform vec3 	LightDirWorld;
	uniform int		BoneCount;
	uniform mat4	boneMatrixArray[8];
	uniform mat3 	boneMatrixArrayIT[8];
	
	varying float LightIntensity;
	varying vec2  TexCoord;

	void main(void)
	{
		ivec4 boneIndex = ivec4(inBoneIndex);
		vec4 boneWeights = inBoneWeight;
		
		if(BoneCount>0)
		{
			mat4 boneMatrix = boneMatrixArray[boneIndex.x];
			mat3 normalMatrix = boneMatrixArrayIT[boneIndex.x];

			vec4 position = boneMatrix * vec4(inVertex, 1.0) * boneWeights.x;
			vec3 worldNormal = normalMatrix * inNormal * boneWeights.x;
			
			for (int i = 1; i < 3; ++i)
			{
				if(i<BoneCount)
				{
					// "rotate" the vector components
					boneIndex = boneIndex.yzwx;
					boneWeights = boneWeights.yzwx;
				
					boneMatrix = boneMatrixArray[boneIndex.x];
					normalMatrix = boneMatrixArrayIT[boneIndex.x];

					position += boneMatrix * vec4(inVertex, 1.0) * boneWeights.x;
					worldNormal += normalMatrix * inNormal * boneWeights.x;
				}
			}		
			gl_Position = ViewProjMatrix * position;
			// Simple diffuse lighting
			LightIntensity = max(0.0, dot(normalize(worldNormal), -LightDirWorld));
		}	

		TexCoord = inTexCoord.st;
	}	
	[/GLSL_CODE]	
[/VERTEXSHADER]	
	
[FRAGMENTSHADER]	
	NAME FragShader	
	[GLSL_CODE]	
	uniform sampler2D sTexture;
	
	varying    float LightIntensity;
	varying vec2  TexCoord;
	
	void main()
	{
	    gl_FragColor = texture2D(sTexture, TexCoord) * LightIntensity;
	}
	[/GLSL_CODE]	
[/FRAGMENTSHADER]	
 	
[EFFECT] 	
	NAME		Effect	
		
	ATTRIBUTE	inVertex			POSITION	
	ATTRIBUTE	inNormal			NORMAL
	ATTRIBUTE	inTexCoord			UV0
	ATTRIBUTE	inBoneIndex			BONEINDEX
	ATTRIBUTE	inBoneWeight		BONEWEIGHT
	
	UNIFORM 	LightDirWorld		LIGHTDIRWORLD
	UNIFORM		ViewProjMatrix		VIEWPROJECTION
	UNIFORM		BoneCount			BONECOUNT
	UNIFORM		boneMatrixArray		BONEMATRIXARRAY
	UNIFORM		boneMatrixArrayIT	BONEMATRIXARRAYIT
	
	UNIFORM		sTexture			TEXTURE0

	TEXTURE 0 	base
	
	FRAGMENTSHADER 	FragShader	
	VERTEXSHADER	VertShader	
[/EFFECT]	

